#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    bool lemonadeChange(vector<int>& bills)
    {
        int five = 0, ten = 0;
        for (auto& ch : bills)
        {
            if (ch == 5) five++;
            else if (ch == 10) ten++, five--;
            else
            {
                if (ten > 0)
                {
                    ten--;
                    five--;
                }
                else
                {
                    five -= 3;
                }
            }
            if (five < 0 || ten < 0) return false;
        }
        return true;
    }
};